package com.kai.utils;

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;

import java.io.IOException;


public class ImageToBase64 {
    /*把验证码图片转换成base64*/
    public static String imageToBase64(BufferedImage imagePath){
        String base64 = null;
        try {
            //输出流
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            ImageIO.write(imagePath, "jpeg", stream);
            base64 = Base64.encode(stream.toByteArray());
            stream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return base64;
    }
}
